/*
 * @Author: your name
 * @Date: 2020-03-23 17:20:27
 * @LastEditTime: 2020-04-08 18:32:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \videolibrary\assets\common\filters.js
 */
/**
 * 全局过滤器
 */
import { fmtFileUrl } from "@/js/utils";
import {moment} from "@/dependencies/moment.min.js"

/**
 * 生成服务器地址
 */
export function fmtUrl(token) {
  return fmtFileUrl(token);
}

/**
 * 生成背景图
 */
export function fmtBg(val) {
  return { backgroundImage: `url('${fmtUrl(val)}')` };
}

/**
 * 格式化日期
 */
export function fmtDate(val, str = "YYYY-MM-DD HH:mm:ss") {
  if(val){
    return moment(val).format(str);
  }else{
    return ""
  }
}

/**
 * 生成 时分秒
 */
export function fmtHHmmss(val = 0, fmt = "HH:mm:ss") {
  val = Math.floor(val / 1000);
  var s = val % 60;
  var minSum = Math.floor(val / 60);
  var m = minSum % 60;
  var h = Math.floor(minSum / 60);

  var HH = (h < 10 ? "0" : "") + h;
  var mm = (m < 10 ? "0" : "") + m;
  var ss = (s < 10 ? "0" : "") + s;
  var time= fmt
    .replace("HH", HH)
    .replace("mm", mm)
    .replace("ss", ss);
  if(HH=="00"){
    return time.substring(3,8);
  }
  return time;
}

export function show_red(s_,str_,color_) {
  const result=str_.replace(new RegExp(s_, 'g'), `<span class="primary_title">${s_}</span>`);
  return result;
}
export function btnPermissionControl(btnKey) {
  let result = false;
  let permissionCodes = sessionStorage.getItem("permissionCodes");
  if(permissionCodes != 0){
    permissionCodes = permissionCodes.split(",");
    permissionCodes.forEach(item=>{
      if(item == btnKey){
        result = true;
      }
    })
  }
  return result;
}

